//
//  NYMyConsumeRecordCell.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/9.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYMyConsumeRecordCell.h"
@interface NYMyConsumeRecordCell ()
@property (strong, nonatomic)  QMUIGhostButton *headImageBtn;
@property (strong, nonatomic)  TTTAttributedLabel *userNameLabel;
@property (strong, nonatomic)  TTTAttributedLabel *timeLabel;
@property (strong, nonatomic)  QMUIButton *likeBtn;
@property(nonatomic, strong) NYMyConsumeRecordModel *commentModel;
@property(nonatomic, strong) UIView *centerContentView;
@property (strong, nonatomic)  TTTAttributedLabel *commentLabel;
@end
@implementation NYMyConsumeRecordCell
- (BOOL)shouldUpdateCellWithObject:(NYMyConsumeRecordModel *)object
{
        if (![object isKindOfClass:[NYMyConsumeRecordModel class]])
        {
                return NO;
        }
        [self updateContentWithModel:object];
        return YES;
}
+ (CGFloat)heightForObject:(id)object identifier:(NSString *)identifier atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
        return UITableViewAutomaticDimension;
}
- (void)updateContentWithModel:(NYMyConsumeRecordModel *)model
{
        self.commentModel = model;
        self.headImageBtn.hidden = YES;
        self.userNameLabel.text = NOT_NULL_STRING_DEFAULT_EMPTY(model.product_name);
        self.timeLabel.text = [AppUnit formatGMT8TimeMillisecond:model.buytime.floatValue * 1000 withFormat:@"yyyy-MM-dd HH:mm"];//@"10.13 12:14";
        NSString *startTime = [AppUnit formatGMT8TimeMillisecond:model.vip_start_time.floatValue * 1000 withFormat:@"yyyy-MM-dd HH:mm"];
        NSString *endTime = [AppUnit formatGMT8TimeMillisecond:model.vip_ent_time.floatValue * 1000 withFormat:@"yyyy-MM-dd HH:mm"];
        self.commentLabel.text = [NSString stringWithFormat:@"%@ 价格：%@\n起始时间：%@\n结束时间：%@",model.product_name,model.price,startTime,endTime];
        self.likeBtn.hidden = YES;
}

- (void)setupView
{
        [super setupView];
        self.headImageBtn = [[QMUIGhostButton alloc] init];
        self.headImageBtn.ghostColor = [UIColor clearColor];
        self.headImageBtn.clipsToBounds = YES;
        [self.contentView addSubview:self.headImageBtn];
        
        self.userNameLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
        self.userNameLabel.font = WGSystem12Font;
        self.userNameLabel.textColor = UIColorHex(0x999999);
        self.userNameLabel.textAlignment = NSTextAlignmentLeft;
        
        self.timeLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
        self.timeLabel.font    = WGSystem12Font;
        self.timeLabel.textColor = UIColorHex(0x999999);
        self.timeLabel.textAlignment = NSTextAlignmentLeft;
        
        UIStackView *stackView = [[UIStackView alloc] initWithArrangedSubviews:@[self.userNameLabel,self.timeLabel]];
        stackView.axis = UILayoutConstraintAxisVertical;
        stackView.distribution = UIStackViewDistributionFillProportionally;
        stackView.alignment = UIStackViewAlignmentFill;
        stackView.spacing = 2;
        [self.contentView addSubview:stackView];
        
        self.likeBtn = [[QMUIButton alloc] init];
        self.likeBtn.imageEdgeInsets = UIEdgeInsetsMake(-2.5, 0, 0, 0);
        self.likeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        self.likeBtn.spacingBetweenImageAndTitle = 4;
        self.likeBtn.titleLabel.font = WGSystem12Font;
        [self.likeBtn setTitleColor:UIColorHex(0x999999) forState:(UIControlStateNormal)];
        [self.likeBtn setTitleColor:UIColorHex(0xf6645f) forState:UIControlStateSelected];
        [self.likeBtn setImage:[UIImage comment_btn_like_nor] forState:UIControlStateNormal];
        [self.likeBtn setImage:[UIImage comment_btn_like_sel] forState:UIControlStateSelected];
        [self.likeBtn setTitle:@"0" forState:(UIControlStateNormal)];
        [self.likeBtn setTitle:@"0" forState:(UIControlStateSelected)];
        [self.contentView addSubview:self.likeBtn];
        
        self.centerContentView = [[UIView alloc] init];
        self.centerContentView.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:self.centerContentView];
        
        [self.headImageBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.contentView).offset(__WGWidth(14.0f));
                make.left.equalTo(self.contentView).offset(__WGWidth(14.0f));
                make.height.mas_equalTo(__WGWidth(30.0f));
                make.width.mas_equalTo(0);
        }];
        
        [stackView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(self.headImageBtn);
                make.left.equalTo(self.headImageBtn.mas_right).offset(__WGWidth(10.0f));
                make.right.lessThanOrEqualTo(self.likeBtn.mas_left).offset(-__WGWidth(8.0f));
        }];
        
        [self.likeBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(self.headImageBtn.mas_centerY).offset(-self.likeBtn.imageEdgeInsets.top);
                make.right.equalTo(self.contentView.mas_right).offset(__WGWidth(-10.0f));
                make.width.mas_equalTo(__WGWidth(0));
                make.height.mas_equalTo(__WGHeight(30.0f));
        }];
        
        
        [self.centerContentView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(stackView.mas_bottom);
                make.left.equalTo(stackView.mas_left);
                make.right.equalTo(self.likeBtn.imageView.mas_right);
                make.bottom.equalTo(self.contentView.mas_bottom).priorityHigh();
        }];
        
        self.commentLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
        self.commentLabel.numberOfLines = 0;
        self.commentLabel.backgroundColor = [UIColor clearColor];
        self.commentLabel.font  = WGSystem14Font;
        //        self.commentLabel.textInsets = UIEdgeInsetsMake(5, 5, 5, 5);
        self.commentLabel.lineSpacing = 3;
        [self.centerContentView addSubview:self.commentLabel];
        
        
        [self.commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.centerContentView).offset(__WGWidth(12.0f));
                make.left.equalTo(self.centerContentView);
                make.right.equalTo(self.centerContentView);
                make.bottom.equalTo(self.centerContentView).offset(__WGWidth(-7.0f));
        }];
}


@end
